<%--
  Created by IntelliJ IDEA.
  User: 鑫
  Date: 2022/4/10
  Time: 14:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript">
        window.onload=function () {
            document.getElementById("btn01").onclick=function () {
                alert("11")
                var xmlHttpRequest = new XMLHttpRequest();
                xmlHttpRequest.open("GET","http://localhost:8080/Ajax/ajaxServlet?action=testAjax",true);
                xmlHttpRequest.onreadystatechange=function () {
                    if (xmlHttpRequest.readyState==4&&xmlHttpRequest.status==200){
                        //解析Json格式的字符串
                        var jsonobj = JSON.parse(xmlHttpRequest.responseText);
                        // $("#text1").val(jsonobj.username);
                        alert(jsonobj.username);
                        alert("aaa")
                        $("text1").val(jsonobj.username);

                    }
                }
                xmlHttpRequest.send();
            }
        }
    </script>
</head>
<body>
<div id="div01"></div>
<button id="btn01">测试ajax</button>
<input id="text1" type="text" value="">
</body>
</html>
